﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinalProject.Data.EntityRepositories.Interfaces;
using FinalProject.Data.DBInteractions.Interfaces;
using FinalProject.Services.Interfaces;
using FinalProject.Entities;
using FinalProject.Data.Search;

namespace FinalProject.Services.Services
{
    public class ItemTextureService : IItemTextureService
    {
        private readonly IItemTextureRepository _repository;
        private readonly IUnitOfWork _unitOfWork;
        public ItemTextureService(IItemTextureRepository repository, IUnitOfWork unitOfWork)
        {
            this._repository = repository;
            this._unitOfWork = unitOfWork;
        }

        #region Members

        public PagedListResult<Entities.ItemTexture> GetAll()
        {
            var entities = _repository.Search(new SearchQuery<ItemTexture>());
            return entities;
        }

        public Entities.ItemTexture GetById(int id)
        {
            var entity = _repository.GetById(id);
            return entity;
        }

        public void Create(Entities.ItemTexture entity)
        {
            _repository.Add(entity);
            _unitOfWork.Commit();
        }

        public void Update(Entities.ItemTexture entity)
        {
            _repository.Update(entity);
            _unitOfWork.Commit();
        }

        public void Delete(int id)
        {
            var entity = _repository.GetById(id);
            _repository.Delete(entity);
            _unitOfWork.Commit();
        }

        public void Save()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
